package com.wanmait.wisdom.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wisdom.entity.Payment;
import com.wanmait.wisdom.manage.service.ManagePaymentService;
import com.wanmait.wisdom.mapper.PaymentMapper;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class ManagePaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements ManagePaymentService {
    @Resource
    private PaymentMapper paymentMapper;
    @Resource
    private RedisTemplate<String,Object> redisTemplate;


    @Override
    @Cacheable("paymentList")
    public List<Payment> findAllPayment() {
        LambdaQueryWrapper<Payment> queryWrapper = new LambdaQueryWrapper<>();
        redisTemplate.opsForValue().set("paymentList",paymentMapper.selectList(queryWrapper.orderByAsc(Payment::getSort)),1, TimeUnit.HOURS);
        return paymentMapper.selectList(queryWrapper.orderByAsc(Payment::getSort));
    }

    // 省略其他代码...


}
